package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.damgesource.SkillDamageSource;
import net.xxcxcxcx.xc_enhancedmob.math.IntToRoman;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class BlockSkill extends BaseSkill {

    public BlockSkill(int level) {
        super(level);
    }

    public BlockSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public BlockSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setCooldown(200);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("阻隔技能，每隔 %d tick获得一次的伤害免疫，每级-10%%冷却。", skillConfig.getCooldown());
    }

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return getSkilltime() < mobEntity.world.getTime();
    }

    @Override
    public Integer getCooldown() {
        return (int) (super.getCooldown() * IntToRoman.pow(0.9f, getSkillLevel())) + 1;
    }

    @Override
    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (source instanceof SkillDamageSource source1 && source1.getPassSkill()) return true;
        if (canUseAbility(target)) {
            setSkilltime(target.world.getTime() + getCooldown());
            amount.setValue(0f);
            return false;
        }
        return true;
    }


}
